/*
 *  $Id: Imp.cs 1058 2010-05-19 15:44:27Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Creatures {
    public class Imp: DemonCreatureCard {
        public Imp(): base("001_d_c_imp") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Darkness;
            Value = 100;
            Damage = 1;
            Health = 2;
            AddManaCost(ElementType.Darkness, 1);
            PactValue = 1;
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.Cannibal>();
        }

        public override void ExecutePact(Player owner) {
            owner.AddAffect<ImpAffect>();
        }

        private class ImpAffect: SpellAffect<Imp> {
            public ImpAffect(): base(true) {
                DefaultName = true;
                DefaultDescription = true;
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnCreatureSummon += DoSummon;
                EnemySummary.OnCreatureSummon += DoSummon;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnCreatureSummon -= DoSummon;
                EnemySummary.OnCreatureSummon -= DoSummon;
            }

            private void DoSummon(Creature cr) {
                if (cr.Card.Element != ElementType.Darkness) return;
                Remove();
                cr.Owner.AddAffect(new ImpBuffAffect(cr.Health));
            }
        }

        private class ImpBuffAffect: SpellAffect<Imp> {
            private TimeAffect _time;

            public ImpBuffAffect(int value): base(true) {
                DefaultName = true;
                DefaultDescription = true;
                _time = new TimeAffect(value*4, new Affects.ManaIncome(ElementType.Darkness, 1));
                Add(_time);
            }

            public override string Id {
                get { return AffectManager.GetCardId<Imp>("buff"); }
            }

            public override string DescriptionText {
                get { return Description.GetText((_time.Phases+3)/4); }
            }

            public override void Dispell() {
                Owner.DamageBy(NewDamage(DamageType.Darkness, 1));
                base.Dispell();
            }
        }
    }
}
